using UnityEngine;

namespace Lean.Localization
{
	[ExecuteInEditMode]
	[DisallowMultipleComponent]
	[RequireComponent(typeof(AudioSource))]
	public class LeanLocalizedAudioSource : LeanLocalizedBehaviour
	{
		[Tooltip("If PhraseName couldn't be found, this clip will be used")]
		public AudioClip FallbackAudioClip;

		public override void UpdateTranslation(LeanTranslation translation)
		{
			AudioSource component = GetComponent<AudioSource>();
			if (translation != null)
			{
				component.clip = (translation.Object as AudioClip);
			}
			else
			{
				component.clip = FallbackAudioClip;
			}
		}

		protected virtual void Awake()
		{
			if (FallbackAudioClip == null)
			{
				AudioSource component = GetComponent<AudioSource>();
				FallbackAudioClip = component.clip;
			}
		}
	}
}
